package tt.dz.biz.service.cardno;

import tt.dz.biz.dao.financial.MerchantDAO;
import tt.dz.common.AppContxtUtil;
import tt.dz.common.BusinessException;
import tt.dz.common.DzConstants;
import tt.dz.common.DzConstants.CardBIN;
import tt.dz.common.DzConstants.CardType;
import tt.dz.vo.MerchantVO;

public class DefaulCardNoDirector
  implements CardNoDirector
{
  private static final MerchantDAO MERCHANT_DAO = (MerchantDAO)AppContxtUtil.getBean("merchantDAO");
  private String cardType;
  private String cardBin;
  private String merchantCode;
  private String areaCode;
  private CardNoSequenceGenerator cardNoSequeueGenerator;
  private CardNoBuilder builder;
  
  public DefaulCardNoDirector(String cardType, String cardBin, String merchantCode, String areaCode, CardNoSequenceGenerator cardNoSequeueGenerator)
  {
    this.cardType = cardType;
    this.cardBin = cardBin;
    this.merchantCode = merchantCode;
    this.areaCode = areaCode;
    this.cardNoSequeueGenerator = cardNoSequeueGenerator;
  }
  
  public void setBuilder(CardNoBuilder builder)
  {
    this.builder = builder;
  }
  
  public <T extends CardNoProduct> T[] product(int productCount)
    throws BusinessException
  {
    DzConstants.CardBIN cardBIN = DzConstants.CardBIN.indexOf(this.cardBin);
    this.builder.setCardBin(cardBIN);
    DzConstants.CardType cardType = DzConstants.CardType.indexOf(this.cardType);
    this.builder.setCardType(cardType);
    MerchantVO vo = MERCHANT_DAO.queryMerchantByCode(this.merchantCode);
    this.builder.setMerchant(vo);
    this.builder.setAreaCode(this.areaCode);
    this.builder.setSequenceGenerator(this.cardNoSequeueGenerator);
    return this.builder.product(productCount);
  }
}
